package pojo;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/02/17
 * @description 建造模式模板
 * 一般目标类会提供private final属性，和私有化构造方法
 * 同时提供public静态内部类，即为建造器，及其公开的静态方法builder()
 */
public class Customer {
    private final Integer id;
    private final String name;
    private final String phone;

    private Customer(Integer id, String name, String phone) {
        this.id = id;
        this.name = name;
        this.phone = phone;
    }

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getPhone() {
        return phone;
    }

    @Override
    public String toString() {
        return "Customer{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", phone='" + phone + '\'' +
                '}';
    }
    public static CustomerBuilder builder() {
        return new CustomerBuilder();
    }
    /**
     * 公开的静态内部类，就是建造器
     * 里面有私有属性，不是final的
     * 对外提供同名方法，设定值
     * 再提供建造对象的核心方法build()
     */
    public static class CustomerBuilder {
        private Integer id;
        private String name;
        private String phone;
        public CustomerBuilder id(Integer id) {
            this.id = id;
            return this;
        }
        public CustomerBuilder name(String name) {
            this.name = name;
            return this;
        }
        public CustomerBuilder phone(String phone) {
            this.phone = phone;
            return this;
        }
        // 建造对象的核心方法
        public Customer build() {
            return new Customer(id, name, phone);
        }
    }
}
